<!DOCTYPE html>
<?php
include "Redirect.php";

session_start();
if (!isset($_SESSION['uid'])) {

    redirect("401.html");
    exit;
}
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link type="text/css" rel="stylesheet" href="css/bootstrap.css"/>
        <link type="text/css" rel="stylesheet" href="css/mural.css"/>
        <link rel="shortcut icon" href="img/kiwicon.ico">
        <title>Kiwitter</title>
    </head>
    <body>

        <div class="navbar navbar-fixed-top">
            <div class="navbar-inner">
                <div class="container">
                    <a class="brand" href="index.php">Kiwitter</a>
                    <div class="nav-collapse">
                        <ul class="nav">
                            <li class=""><a href="index.php">Inicio</a></li>
                            <li class="dropdown">
                                <a data-toggle="dropdown" class="dropdown-toggle" href="#">Mural<b class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    <li><a href="mural.php?filter=all" 
                                           title="Visualize todos os Kiwittes.">
                                            Todos os Kiwittes
                                        </a>
                                    </li>
                                    <li>
                                        <a href="mural.php?filter=user" 
                                           title="Visualize apenas os Kiwittes os quais realizou ou comentou.">
                                            Meus Kiwittes
                                        </a>
                                    </li>
                                </ul>
                            </li>
                        </ul>
                        <ul class="nav pull-right">
                            <li class="divider-vertical"></li>
                            <li class="dropdown">
                                <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                                    <?php echo($_SESSION['username']); ?><b class="caret"></b>
                                </a>
                                <ul class="dropdown-menu">
                                    <li><a href="perfil.php">Meus dados</a></li>
                                    <li class="divider"></li>
                                    <li><a href="SessionControl.php?action=logout">Sair</a></li>
                                </ul>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <div class="container">
            <div class="offset1 span10">
                <form method="post" action="mural.php">
                        <textarea placeholder="Diga-nos, o que você está pensando..." 
                                  name="msgM" id="msgM" rows="4" cols="64" class="span10" 
                                  style="resize: none" maxlength="512"></textarea><br>
                        <input type="submit" id="envia" value="Kiwitte!" class="btn">
                    </form>
                <ul class="thumbnails">

                    <?php
                    include "DBconf.php";
                    include "muralFunctions.php";

                    $kiwitte = '';
                    $comment = '';

                    if (isset($_POST['msgM']))
                        $kiwitte = $_POST['msgM'];
                    if (isset($_POST['msgC']))
                        $comment = $_POST['msgC'];
                    if (isset($_POST['idC']))
                        $kiwitteid = $_POST['idC'];

                    $connect = mysql_connect($server, $db_user, $db_pass);
                    $userid = $_SESSION['uid'];

                    if (mysql_select_db($db_name, $connect)) {
                        if (!empty($kiwitte))
                            addKiwitte($connect, $kiwitte, $userid);
                        else if ($comment != '')
                            addComments($connect, $comment, $userid, $kiwitteid);

                        if (isset($_GET['filter']) && $_GET['filter'] == 'user')
                            showKiwittes($connect, $_SESSION['uid']);
                        else
                            showKiwittes($connect);
                    }
                    else {
                        echo "DB problems";
                    }
                    ?>

                </ul>
            </div>
        </div>
        <script type="text/javascript" src="js/jQuery-1.7.1-min.js"></script>
        <script type="text/javascript" src="js/bootstrap-2.0.3.js"></script>
        <script type="text/javascript" src="js/mural.js"></script>
    </body>
</html>